import { sickbed_approval } from '@/services/sickbeds';
import { ActionType, ProForm, ProFormTextArea } from '@ant-design/pro-components';
import { Divider, Modal, message } from 'antd';
import { values } from 'lodash';
import React from 'react'

interface Iprops {
    isShowRefuseModal: (show: boolean) => void;
    isRefuseModalOpen: boolean;
    id: number | undefined;
    actionRef: React.MutableRefObject<ActionType | undefined>;
}
const Refuse = (props: Iprops) => {
    const { isRefuseModalOpen, isShowRefuseModal, id, actionRef } = props

    // 点击取消的回调
    const onReset = () => {
        isShowRefuseModal(false);
    };

    // 拒绝建床
    const ConfirmRefuse = async (values: any) => {
        let res: any = await sickbed_approval({ id, ...values, status: 2 })
        if (res.code == 200) {
            // 刷新列表
            actionRef.current?.reload()
            message.success('拒绝建床成功');
            // 关闭弹窗
            isShowRefuseModal(false)
        } else {
            message.error(res.msg)
        }
    }
    return (
        <Modal
            title="拒绝建床"
            centered
            open={isRefuseModalOpen}
            onCancel={() => isShowRefuseModal(false)}
            destroyOnClose={true}
            width={400}
            footer={null}
        >
            <Divider />
            <ProForm
                layout='horizontal'
                onReset={() => onReset()}
                onFinish={async (values) => ConfirmRefuse(values)}
                submitter={{
                    // 配置按钮文本
                    searchConfig: {
                        resetText: '取消',
                        submitText: '提交',
                    },
                    resetButtonProps: {
                        style: {
                            // 隐藏重置按钮
                            display: 'block',
                            position: 'absolute',
                            left: 'calc(50% - 107px)',
                        },
                    },
                    submitButtonProps: {
                        style: {
                            display: 'block',
                            position: 'absolute',
                            right: 'calc(50% - 107px)',
                        },
                    },
                }}
            >
                <ProFormTextArea
                    name="reason"
                    label="拒绝原因:"
                    placeholder="请填写拒绝原因!"
                    rules={[
                        { required: true, message: '请填写拒绝建床原因' },
                        {
                            max: 100,
                            message: '字数最多100个字符',
                        },
                        { pattern: /(^\S)((.)*\S)?(\S*$)/, message: '不能输入空格' },
                    ]}
                />
                <br />
            </ProForm>
            <br />
        </Modal>
    )
}
export default Refuse